#TP0 de AEDS 3
#TAD BigNum
#
#MAKEFILE
#
# Aluno: Douglas Rodrigues de Almeida
# Mail: douglasralmeida@hotmail.com

BINARY_NAME = tp0
CC = gcc
BINARIES_DIR = $(shell cd ../bin)
INCLUDE_DIR = $(shell cd ../include)
OBJECTS_DIR = $(shell cd ../obj)
SCRIPTS_DIR = $(shell cd ../scripts)
SOURCES_DIR = $(shell cd ../src)
OBJECTS = $(SOURCES:.c=.o)
SOURCES = $(shell cd $(SOURCES_DIR) && ls *.c)
DEPENDENCIES = $(foreach dep, $(OBJECTS), $(OBJECTS_DIR)/$(dep))
CFLAGS = -c -Wall -I$(INCLUDE_DIR)

.c.o:
	-@echo "Compiling..."
	$(CC) $(CFLAGS) $< -o $@

all:
	-@ echo "Creating links..."
	-@ make create-links
	-@ make $(BINARIES_DIR)/$(BINARY_NAME)
	-@ echo "Removing links..."
	-@ make remove-links

create-links:
	-@ $(foreach file, $(SOURCES), $(shell ln -fs $(SOURCES_DIR)/$(file) $(OBJECTS_DIR)/$(file)))

remove-links:
	-@ rm -rf $(OBJECTS_DIR)/*.c

$(BINARIES_DIR)/$(BINARY_NAME): $(DEPENDENCIES)
	-@ echo "Build executable..."
	$(CC) $(DEPENDENCIES) -o $(BINARIES_DIR)/$(BINARY_NAME)


depend:
	-@ echo "Solving dependencies..."
	-@ cd $(SOURCES_DIR) && makedepend -Y *.c -I$(INCLUDE_DIR) -p$(OBJECTS_DIR)/ -f$(SCRIPTS_DIR)/makefile
